import os
from openai import OpenAI
from langchain_openai import ChatOpenAI
from pymilvus import connections

#embedding
"""def get_embeddings(input_text):
    client = OpenAI(
        api_key=os.getenv("JINA_API_KEY"),
        base_url="https://api.jina.ai/v1/embeddings",
    )
    completion = client.embeddings.create(
        model="jina-embeddings-v3",
        input=input_text,
        encoding_format="float"
    )#text-embedding-v3 token已用完
    return completion.data[0].embedding

os.environ["JINA_API_KEY"] = ""
"""
import requests
os.environ["JINA_API_KEY"] = "jina_0806183d486d4057a8822c3f11cc59adq36ajgW3bQbNE7AT5m9qANB1uOye"
def get_embeddings(input_text):
    url = "https://api.jina.ai/v1/embeddings"
    headers = {
        "Authorization": f"Bearer {os.getenv('JINA_API_KEY')}",
        "Content-Type": "application/json"
    }
    data = {
        "input": input_text,
        "model": "jina-embeddings-v3"
    }
    response = requests.post(url, json=data, headers=headers)
    if response.status_code == 200:
        return response.json()["data"][0]["embedding"]
    else:
        raise RuntimeError(f"Jina API failed: {response.status_code}, {response.text}")

#milvus
connections.connect("default", host="localhost", port="19530")

#llm
llm = ChatOpenAI(
    api_key="sk-514de7e7f4614e7088aea369174c4ced",
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    model="qwen3-235b-a22b",
    stream=False,
    # Qwen3模型通过enable_thinking参数控制思考过程（开源版默认True，商业版默认False）
    # 使用Qwen3开源版模型时，请将下行取消注释，否则会报错
    extra_body={"enable_thinking": False},
)
